home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / What's New? / Development Kits / Mac OS / USB DDK 1.4.6f4 / Examples / USBEnetSample / ShimEnetStub.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-08-23  |  3.7 KB  |  154 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        ShimEnetStub.c
  3.  
  4.     Contains:    xxx put contents here xxx
  5.  
  6.     Version:    xxx put version here xxx
  7.  
  8.     Copyright:    © 1998-2000 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     File Ownership:
  11.  
  12.         DRI:                xxx put dri here xxx
  13.  
  14.         Other Contact:        xxx put other contact here xxx
  15.  
  16.         Technology:            xxx put technology here xxx
  17.  
  18. */
  19.  
  20. #include <Errors.h>
  21. #include <LowMem.h>
  22. #include <TextUtils.h>
  23.  
  24. #include "USBEnet.h"
  25. #include "USBEnetVersion.h"
  26. #include "ShimEnetStub.h"
  27.  
  28. /***********************************************************************************/
  29. //    Function:        InstallShimDrvr(CFragConnectionID    ConnID)
  30. //    Description:    Handles the interface with the shim install
  31. //
  32. //    Input:            CFrag Connection ID (mine)
  33. //    Output:            Results
  34. /***********************************************************************************/
  35.  
  36. OSErr InstallShimDrvr(CFragConnectionID    ConnID)
  37. {
  38.     OSErr                 err;
  39.     ShimRefNum            Tref;            // need to do this cause occasionally the globals get lost
  40.                                         // passing the address to the Shim (it switches zones)
  41.     EnetShimInterface    IntBlk;
  42.     
  43.     TraceMessage(0, kDrvName"- Entering InstallShimDrvr");
  44.     
  45.     err = LoadShim();
  46.     if (err == noErr)
  47.     {    
  48.         IntBlk.DRVName = (unsigned char *)&gGlobals->rname;
  49.         IntBlk.RefCon = 0;
  50.         IntBlk.ConnID = ConnID;
  51.         IntBlk.theID = (UInt32)&gGlobals->theID;
  52.         err = (*gGlobals->ShimInstall) (IntBlk, &Tref);
  53.         gGlobals->ShimRef = Tref;
  54.     }
  55.     
  56.     return err;
  57. }
  58.  
  59. /***********************************************************************************/
  60. //    Function:        RemoveShimDrvr(Boolean forceFlag)
  61. //    Description:    Handles the interface with the shim remove
  62. //
  63. //    Input:            Orderly or forced
  64. //    Output:            Results
  65. /***********************************************************************************/
  66.  
  67. OSErr RemoveShimDrvr(Boolean forceFlag)
  68. {    
  69.     OSErr     err;
  70.     
  71.     TraceMessage(0, kDrvName"- Entering RemoveShimDrvr");
  72.     
  73.     if (gGlobals->ShimRef != kInvalidRef)
  74.     {
  75.         err = (*gGlobals->ShimRemove) (gGlobals->ShimRef, forceFlag);
  76.         if (err == noErr)
  77.             UnLoadShim();
  78.             
  79.         if (err > 0)                // if it's pending the shim handles from here
  80.             err = noErr;            // but we can't unload yet
  81.             
  82.     } else {
  83.         err = -1;
  84.     }
  85.     
  86.     gGlobals->ShimRef = kInvalidRef;
  87.     return err;
  88. }
  89.  
  90. /***********************************************************************************/
  91. //    Function:        LoadShim
  92. //    Description:    Loads the shim and sets up the various addresses
  93. //
  94. //    Input:            Nothing
  95. //    Output:            Results
  96. /***********************************************************************************/
  97.  
  98. OSErr LoadShim(void)
  99. {
  100.     OSErr                err = noErr;            // Let's assume success
  101.     Ptr                    FragAddr;
  102.     CFragConnectionID    ConnID;
  103.     Str255                errMsg;
  104.     CFragSymbolClass    cClass;
  105.     
  106.     err = GetSharedLibrary("\pEnetShimLib", kPowerPCCFragArch, kLoadCFrag, &ConnID, &FragAddr, errMsg);
  107.     if (err == noErr)
  108.     {
  109.         gGlobals->ConnID = ConnID;
  110.         err = FindSymbol(ConnID, Shim_Install, (Ptr *)&gGlobals->ShimInstall, &cClass);
  111.         if ((err != noErr) || (cClass != kTVectorCFragSymbol)) 
  112.         {
  113.             err = -1;
  114.         }
  115.         
  116.         if (err == noErr)
  117.         {
  118.             err = FindSymbol(ConnID, Shim_Remove, (Ptr *)&gGlobals->ShimRemove, &cClass);
  119.             if ((err != noErr) || (cClass != kTVectorCFragSymbol)) 
  120.             {
  121.                 err = -1;
  122.             }
  123.         }
  124.         
  125.         if (err == noErr)
  126.         {
  127.             err = FindSymbol(ConnID, Shim_Async, (Ptr *)&gGlobals->ShimAsync, &cClass);
  128.             if ((err != noErr) || (cClass != kTVectorCFragSymbol)) 
  129.             {
  130.                 err = -1;
  131.             }
  132.         }
  133.     }
  134.  
  135.     return err;
  136. }
  137.  
  138. /***********************************************************************************/
  139. //    Function:        UnLoadShim
  140. //    Description:    UnLoads the shim, actually closes the connection
  141. //
  142. //    Input:            Nothing
  143. //    Output:            Results
  144. /***********************************************************************************/
  145.  
  146. OSErr UnLoadShim(void)
  147. {
  148.     OSErr    err = noErr;            // Let's assume success
  149.     
  150.     err = CloseConnection(&gGlobals->ConnID);
  151.     
  152.     return err;
  153.  
  154. }